package com.zkkz.boot.restTemplate.manager;

import cn.hutool.json.JSONUtil;
import com.zkkz.boot.restTemplate.pojo.ResultResp;
import com.zkkz.boot.restTemplate.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * create by Chas_tsj
 * 2024/7/24 10:31:36
 **/

@Slf4j
@Component
public class WebManager {
    @Resource
    private RestTemplate restTemplate;
    @Value("${wc.url:http://wisdom-campus/wc/}")
    private String wcUrlPrefix;
    private static final String testRemoteCallCampusTest = "web/testRemoteCallCampusTest";
    public User testRemoteCallCampusTest() {
        String url = wcUrlPrefix+testRemoteCallCampusTest;
//        ResultResp resultResp = this.restTemplate.getForObject("http://localhost:8080/web/campusTest", ResultResp.class);
        ResultResp resultResp = this.restTemplate.postForObject(url, null, ResultResp.class);
        log.info("resultResp: {}", resultResp);
        String jsonStr = JSONUtil.toJsonStr(resultResp.getData());
        User user = JSONUtil.toBean(jsonStr, User.class);
        return user;
    }
}
